package com.lichong.quartzdemo.job.controller;


import com.lichong.quartzdemo.job.entity.Response;
import com.lichong.quartzdemo.job.entity.TbJob;
import com.lichong.quartzdemo.job.service.IJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 定时任务表 前端控制器
 * </p>
 *
 * @author lichong
 * @since 2020-07-30
 */
@RestController
@RequestMapping("/job")
public class JobController {
    @Autowired
    private IJobService jobService;

    @GetMapping("test")
    public Response test() {
        return new Response().success();
    }
    @PostMapping("add")
    public Response addJob(TbJob job) {
        this.jobService.createJob(job);
        return new Response().success();
    }

    @GetMapping("delete/{jobId}")
    public Response deleteJob(@PathVariable String jobId) {
        this.jobService.deleteJobs(jobId);
        return new Response().success();
    }

    @PostMapping("update")
    public Response updateJob(TbJob job) {
        this.jobService.updateJob(job);
        return new Response().success();
    }

    @GetMapping("run/{jobId}")
    public Response runJob(@PathVariable String jobId) {
        this.jobService.run(jobId);
        return new Response().success();
    }

    @GetMapping("pause/{jobId}")
    public Response pauseJob(@PathVariable String jobId) {
        this.jobService.pause(jobId);
        return new Response().success();
    }

    @GetMapping("resume/{jobId}")
    public Response resumeJob(@PathVariable String jobId) {
        this.jobService.resume(jobId);
        return new Response().success();
    }
}
